查看原文
其他

明天就是七夕,还来得及,程序猿七夕最强脱单送礼攻略(附代码)

博文 生信者言 2022-03-29

亲爱的姑娘,你一直是我心里最亮的那颗星


亲爱的姑娘,你看到七夕的月光了吗


亲爱的姑娘,前方的路还很长,你要跟我一起走吗

亲爱的姑娘,这是一个程序猿能想到的最好的浪漫


Just For You.



/End.





代码附上:


library(grid)library(dplyr) pdf("my_love.pdf") grid.newpage() pushViewport(viewport(xscale=c(0, 1), yscale=c(0.5, 1),clip=TRUE)) res <- 50for (i in 1:res){    grid.rect(y=1 - (i-1) / res, just="top",              gp=gpar(col=NULL, fill=grey(0.5*i/res))) } moon <- function(x, y, size) {    angle <- seq(-90, 90, length=50)/180*pi    x1 <- x + size*cos(angle)    y1 <- y + size*sin(angle)    mod <- 0.8    x2 <- x + mod*(x1 - x)    grid.polygon(c(x1, rev(x2)), c(y1, rev(y1)),                 default.unit="native",                 gp=gpar(col=NULL, fill="white")) } moon(0.1, 0.9, 0.03) star <- function(x, y, size) {    x1 <- c(x, x + size*.1, x + size*.5, x + size*.1,            x, x - size*.1, x - size*.5, x - size*.1) + .05    y1 <- c(y - size, y - size*.1, y, y + size*.1,            y + size*.7, y + size*.1, y, y - size*.1) + .05    grid.polygon(x1, y1,                 default.unit="native",                 gp=gpar(col=NULL, fill="white")) } star(.5, .7, .02) star(.8, .9, .02) star(.72, .74, .02) star(.62, .88, .02) grid.circle(runif(20, .2, 1), runif(20, .6, 1), r=.002,            default.unit="native",            gp=gpar(col=NULL, fill="white")) hill <- function(height=0.1, col="black") {    n <- 100    x <- seq(0, 1, length=n)    y1 <- sin(runif(1) + x*2*pi)    y2 <- sin(runif(1) + x*4*pi)    y3 <- sin(runif(1) + x*8*pi)    y <- 0.6 + height*((y1 + y2 + y3)/3)    grid.polygon(c(x, rev(x)), c(y, rep(0, n)),                 default.unit="native",                 gp=gpar(col=NULL, fill=col)) } hill() grid.text("I love you not because who you are,\nbut because who I am when I am with you.", gp = gpar(col = "white", cex = 1.2), x = 0.69, y = 0.7)### plot imageim <- read.table("image.txt", header = T) #请点击阅读原文获取网盘文件im <- im[rev(rownames(im)), ] im <- as.matrix(im) grid.imageFun <- function(nrow, ncol, cols,byrow=TRUE){    x <- (1:ncol)/ncol    y <- (1:nrow)/nrow    if (byrow) {        right <- rep(x, nrow)        top <- rep(y, each=ncol)    } else{        right <- rep(x, each=nrow)        top <- rep(y, ncol)    }    grid.rect(x=right, y=top,              width=1/ncol, height=1/nrow,              just=c("right", "top"),              gp=gpar(col=NA, fill=cols),              name="image") } pushViewport(viewport(0.27, 0.34, height = 0.4, width = 0.3)) grid.imageFun(567,567, im, byrow = F)#### hearttheta = seq(-3 * pi, 3 * pi, length = 300) x = cos(theta) y = x + sin(theta) i <- -2*pi df <- as.data.frame(cbind(x,y)) df <- df[df$x >0, ] df1 <- df[df$y > 1,] df1 <- arrange(df1, x)#lines(df1$x, df1$y, col = "red")df2 <- df[df$y <= 1,] df2 <- arrange(df2, desc(y)) dfa <- rbind(df1, df2) dfa$x <- i * dfa$x i <- 2*pi df <- as.data.frame(cbind(x,y)) df <- df[df$x >0, ] df1 <- df[df$y > 1,] df1 <- arrange(df1, x)#lines(df1$x, df1$y, col = "red")df2 <- df[df$y <= 1,] df2 <- arrange(df2, desc(y)) dfb <- rbind(df1, df2) dfb$x <- i * dfb$x dfb <- dfb[rev(rownames(dfb)),] dfc <- rbind(dfa, dfb) rownames(dfc) <- 1:nrow(dfc) dfc[1, ] <- c(0, 1) dfc[nrow(dfc), ] <- c(0, 1) dfc$x <- dfc$x + abs(min(dfc$x)) dfc$y <- dfc$y + abs(min(dfc$y)) dfc$x <- dfc$x / max(dfc$x) dfc$y <- dfc$y / max(dfc$y) popViewport() pushViewport(viewport(0.26, 0.5, height = 0.06,                      width = 0.08, xscale = range(dfc$x),                      yscale = range(dfc$y))) grid.polygon(dfc$x, dfc$y, gp = gpar(fill = "red")) dev.off()



您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存